def solve():
n, m, x, y, d = map(int, input().split())
if (y - d <= 1 or x + d >= n) and (y + d >= m or x - d <= 1):
print(-1)
else:
print(n+m-2)
if __name__ == '__main__':
t = int(input())
for i in range(t):
solve()
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define PI 3.14159265358979323846
#define MOD 1000000007
#define set_bits __builtin_popcountll
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//--------------------------------------------------------------------------//
//Pre-Defined Functions:
//Finding Nearest Power Of 2 Of Any Number--->O(log(n))
int near_pow(int q){
int ans = (int)log2(q);
return pow(2,ans);
}
void input_vector(vector<int> &v,int &n){
for(int i{}; i<n; i++){
int a{}; cin>>a; v.push_back(a);
}
}
//-------------------------------------------------------------------------//
void tarankaaa(){
int n{},m{},x{},y{},d{};
cin>>n>>m>>x>>y>>d;
if(x-d<=1 && y-d<=1){cout<<-1<<endl; return;}
if(x+d>=n && y+d>=m){cout<<-1<<endl; return;}
if(x-d<=1 && x+d>=n){cout<<-1<<endl; return;}
if(y-d<=1 && y+d>=m){cout<<-1<<endl; return;}
cout<<n+m-2<<endl;
}
//--------------------------------------------------------------------------//
int32_t main(){
#ifndef ONLINE_JUDGE
//for getting input from input.txt
freopen("input1.txt", "r", stdin);
//for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
fastio();
int t{1};
cin>>t;
while(t--){
tarankaaa();
}
}
426A - Sereja and Mugs | 363A - Soroban |
1585C - Minimize Distance | 1506E - Restoring the Permutation |
1539A - Contest Start | 363D - Renting Bikes |
1198D - Rectangle Painting 1 | 1023B - Pair of Toys |
1725A - Accumulation of Dominoes | 1675E - Replace With the Previous Minimize |
839A - Arya and Bran | 16B - Burglar and Matches |
1625B - Elementary Particles | 1725G - Garage |
1725B - Basketball Together | 735A - Ostap and Grasshopper |
1183B - Equalize Prices | 1481A - Space Navigation |
1437B - Reverse Binary Strings | 1362B - Johnny and His Hobbies |
1299A - Anu Has a Function | 1111A - Superhero Transformation |
954A - Diagonal Walking | 39F - Pacifist frogs |
1451C - String Equality | 386A - Second-Price Auction |
1690E - Price Maximization | 282B - Painting Eggs |
440A - Forgotten Episode | 233B - Non-square Equation |